package activity;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.laoxinwen.app.R;
import com.umeng.analytics.MobclickAgent;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Random;

import activity.main.MainActivity;
import bean.News;
import bean.Topic;
import bean.TopicArticleItem;
import bean.wraper.DefaultStringWrapper;
import common.Constants;
import common.DateUtil;
import common.FastAdapter;
import common.HttpCallBack;
import common.MyApp;
import common.MyTheme;
import common.Requester;
import common.ServerConfig;
import common.UserConfig;
import common.UserGuideUtil;
import common.VideoWebChromeClient;
import gallery.BasePicViewerActivity;
import gallery.PicViewData;
import share.LoginHelper;
import share.LoginType;
import share.ShareActivity;
import share.ShareDialog;
import util.LogicUtil;
import util.NetUtil;
import util.ToastUtil;
import view.SlidingMenu;

public class ArticleActivity extends ShareActivity implements View.OnClickListener, LoginHelper.LoginResultListener, VideoWebChromeClient.VideoFullScreenHandler {
    //jscomment
    public static final String INTENT_KEY_NEWS = "news";
    public static final String INTENT_KEY_NEWSGROUP = "newsgroup";
    private static final int TYPE_RELOAD = 1;
    private static final int TYPE_REFRESH_CMT_NUM = 2;
    private FastAdapter adapter;
    private News currentArticle;
    private LoginHelper loginHelper;
    @id(R.id.listView)
    private ListView listView;
    private Topic topic;
    @id(R.id.bt_care)
    private View vCollection;
    @id(R.id.iv_loading)
    private ProgressBar progressBar;
    private Dialog shareDialog;
    @id(R.id.slidingMenu)
    private SlidingMenu slidingMenu;
    @id(R.id.tv_topic_title)
    private TextView tvTopicTitle;
    private String url;
    @id(R.id.bottom_bar)
    private View vBottomBar;
    private PopupWindow fontManagePopup;
    private View modeNightImg;
    private View[] fontItems;
    private Runnable showBottomBar = new Runnable() {
        @Override
        public void run() {
            AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
            alphaAnimation.setDuration(250);
            alphaAnimation.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationEnd(Animation animation) {

                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }

                @Override
                public void onAnimationStart(Animation animation) {
                    vBottomBar.setVisibility(View.VISIBLE);
                }
            });
            vBottomBar.startAnimation(alphaAnimation);
        }
    };

    @Override
    protected void onQqInfoObtained() {
        loginHelper.login(LoginType.QQ);
    }

    @Override
    protected void onWechatInfoObtain() {
        loginHelper.login(LoginType.WECHAT);
    }

    @Override
    protected void onWeiboInfoObtained() {
        loginHelper.login(LoginType.SINA);
    }

    @Override
    public void onLoginFail() {
        loginHelper.dismissDialog();
    }

    @Override
    public void onLoginSucceed() {
        loginHelper.dismissDialog();
    }

    private Runnable hideBottomBar = new Runnable() {
        @Override
        public void run() {
            AlphaAnimation alphaAnimation = new AlphaAnimation(vBottomBar.getAlpha(), 0);
            alphaAnimation.setDuration(250);
            alphaAnimation.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationEnd(Animation animation) {

                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }

                @Override
                public void onAnimationStart(Animation animation) {
                    vBottomBar.setVisibility(View.GONE);
                }
            });
            vBottomBar.startAnimation(alphaAnimation);
        }
    };
    @id(R.id.webView)
    private WebView webView;
    private View.OnClickListener listenerForMenuArticle = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            TopicArticleItem n = (TopicArticleItem) v.getTag(2 << 24);
            currentArticle = new News();
            currentArticle.setId(n.getId());
            currentArticle.setTid(topic.getId());
            currentArticle.setTitle(n.getTitle());
            currentArticle.setSummary(topic.getTitle());
            currentArticle.setImg(n.getImg());
            url = ServerConfig.SERVER_HOST + "/article/" + currentArticle.getId() + "?app=" + ServerConfig.API_VERSION + "&wa";
            slidingMenu.closeMenu();
            loadUrl();
            adapter.notifyDataSetChanged();
        }
    };
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case TYPE_RELOAD:
                    if (NetUtil.isNetworkConnected(ArticleActivity.this)) {
                        loadUrl();
                    } else {
                        showToast(Constants.MSG_NET_ERROR);
                    }
                    break;
                case TYPE_REFRESH_CMT_NUM:
                    freshCmtNum();
                    break;
            }
        }
    };

    public static Intent getIntent(Context context, String artcleId) {
        News news = new News();
        news.setId(artcleId);

        return getIntent(context, news);
    }

    public static Intent getIntent(Context context, News news) {
        Intent it = new Intent(context, ArticleActivity.class);
        it.putExtra(INTENT_KEY_NEWS, news);
        return it;
    }

    public static Intent getIntent(Context context, News news, Topic topic) {
        Intent it = new Intent(context, ArticleActivity.class);
        it.putExtra(INTENT_KEY_NEWS, news);
        it.putExtra(INTENT_KEY_NEWSGROUP, topic);
        return it;
    }

    @Override
    public void finish() {
        if (this.isTaskRoot()) {
            Intent it = new Intent(this, MainActivity.class);
            startActivity(it);
        }
        super.finish();
    }

    private String getSrcUrl() {
        String url = ServerConfig.SERVER_HOST + "/article/" + currentArticle.getId();
        String userId = UserConfig.isLogined() ? UserConfig.getUserInfo().getId() : "0";
        Random r = new Random(System.currentTimeMillis());
        int random = r.nextInt(Integer.MAX_VALUE) + 1000;
        url += "?stamp=" + userId + "_" + System.currentTimeMillis() + random;
        return url;
    }

    @SuppressLint("JavascriptInterface")
    private void loadErrorHtml() {
        webView.clearHistory();
        webView.loadUrl(Constants.ERROR_HTML);
        webView.addJavascriptInterface(new Object() {
            @TargetApi(Build.VERSION_CODES.HONEYCOMB)
            @JavascriptInterface
            public void jsreload(String content) {
                handler.sendEmptyMessage(TYPE_RELOAD);
            }
        }, "Android");
    }

    @SuppressLint("JavascriptInterface")
    private void loadUrl() {
        webView.loadUrl(url);
        webView.addJavascriptInterface(new Object() {
            @TargetApi(Build.VERSION_CODES.HONEYCOMB)
            @JavascriptInterface
            public void jscomment(String focus) {
                try {
                    JSONObject jsonObject = new JSONObject(focus);
                    if (jsonObject.getInt("focus") == 1) {
                        Intent it = CommentActivity.getIntent(ArticleActivity.this, currentArticle.getTid(), null, null, currentArticle.getId());
                        it.setAction(CommentActivity.ACTION_REQUEST_FOCUS);
                        startActivity(it);
                    } else {
                        Intent it = CommentActivity.getIntent(ArticleActivity.this, currentArticle.getTid(), null, null, currentArticle.getId());
                        startActivity(it);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }

            @JavascriptInterface
            public void jsimgview(String content) {
                int i = 0;
                PicViewData data = com.alibaba.fastjson.JSONObject.parseObject(content, PicViewData.class);
                startActivity(BasePicViewerActivity.getIntent(data.getIndex(), data.getImgs(), ArticleActivity.this));
            }

            @JavascriptInterface
            public void jsshare(String content) {
                try {
                    JSONObject jsonObject = new JSONObject(content);
                    String imgUrl = em(currentArticle.getImg()) ? ServerConfig.DEFAULT_SHARE_IMG : currentArticle.getImg();
                    switch (jsonObject.getString("platform")) {
                        case "pyq":
                            shareToWeixinFriendCircle(currentArticle.getTitle(), currentArticle.getSummary(), imgUrl, getSrcUrl());
                            break;
                        case "wx":
                            shareToWeixin(currentArticle.getTitle(), currentArticle.getSummary(), imgUrl, getSrcUrl());
                            break;
                        case "wb":
                            shareToWeibo(currentArticle.getTitle(), currentArticle.getSummary(), imgUrl, getSrcUrl());
                            break;
                    }
                    shareLog();
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }

            @JavascriptInterface
            public void jswa(String content) {
                //startActivity(DigTopicActivity.getIntentForDigArticle(ArticleActivity.this, currentArticle.getId()));
                Intent it = TopicActivity.getIntent(ArticleActivity.this, currentArticle.getTid(), true);
                startActivity(it);
            }

            @JavascriptInterface
            public void jsinfo(String content) {
                try {
                    News tmpArticle = com.alibaba.fastjson.JSONObject.parseObject(content, News.class);
                    currentArticle = tmpArticle;
                    handler.obtainMessage(TYPE_REFRESH_CMT_NUM).sendToTarget();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, "Android");
    }

    @Override
    public void onBackPressed() {
        if (slidingMenu.isMenuOpened()) {
            slidingMenu.closeMenu();
        } else if (webChromeClient.inCustomView()) {
            webChromeClient.onHideCustomView();
        } else if (webView.canGoBack()) {
            webView.goBack();
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public void onClick(View view) {
        hideInputKeyboard();
        switch (view.getId()) {
            case R.id.bt_menu:
                slidingMenu.openMenu();
                break;
            case R.id.bt_share:
                shareNews();
                break;
            case R.id.bt_back:
                finish();
                break;
            case R.id.bt_dig:
//                startActivity(DigTopicActivity.getIntentForDigArticle(ArticleActivity.this, currentArticle.getId()));
                Intent it = TopicActivity.getIntent(ArticleActivity.this, currentArticle.getTid(), true);
                startActivity(it);
                break;
            case R.id.bt_comment:
                startActivity(CommentActivity.getIntent(this, currentArticle.getTid(), null, null, currentArticle.getId()));
                break;
            case R.id.bt_font:
                fontManagePopup.showAtLocation(findViewById(R.id.detail_root), Gravity.BOTTOM, 0, 0);
                modeNightImg.setSelected(UserConfig.isNightMode());
                int cFontSize = UserConfig.getFontSize();
                for (View item : fontItems) {
                    if ((item.getId() == R.id.font_normal && cFontSize == Constants.FONT_SIZE_NORMAL) ||
                            (item.getId() == R.id.font_big && cFontSize == Constants.FONT_SIZE_BIG) ||
                            (item.getId() == R.id.font_large && cFontSize == Constants.FONT_SIZE_LARGE)) {
                        item.setSelected(true);
                    } else {
                        item.setSelected(false);
                    }
                }
                break;
            case R.id.bt_care:
                if (!UserConfig.isLogined()) {
                    showLoginDialog();
                } else {
                    Requester.markCareArticle(currentArticle.getId(), new HttpCallBack<DefaultStringWrapper>() {
                        @Override
                        public void onSucceed(DefaultStringWrapper data) {
                            //                        topic.setAttention(topic.getAttention() == 0 ? 1 : 0);
                            if (vCollection.isSelected()) {
                                ToastUtil.showShortToast("已取消关注");
                            } else {
                                ToastUtil.showShortToast("已关注");
                            }

                            vCollection.setSelected(!vCollection.isSelected());
                        }

                        @Override
                        protected void onServerError(DefaultStringWrapper data) {
                            super.onServerError(data);
                            MainActivity.jumpHereForLogin(ArticleActivity.this);
                        }

                        @Override
                        protected void onNetError() {
                            super.onNetError();
                        }
                    });
                }

                break;
            case R.id.mode_night:
                UserConfig.setNightMode(!UserConfig.isNightMode());
                modeNightImg.setSelected(UserConfig.isNightMode());
                MyApp.switchTheme(UserConfig.isNightMode() ? MyTheme.THEME_NIGHT : UserConfig.getMainTheme());
                restartSelf();
                break;
            case R.id.font_normal:
            case R.id.font_big:
            case R.id.font_large:
                for (View item : fontItems) {
                    item.setSelected(false);
                }
                view.setSelected(true);
                UserConfig.setFontSize(view.getId() == R.id.font_normal ? Constants.FONT_SIZE_NORMAL : (view.getId() == R.id.font_big ? Constants.FONT_SIZE_BIG : Constants.FONT_SIZE_LARGE));
                url = LogicUtil.getArticleUrl(currentArticle.getId(), null == topic);
//                int opos = webView.getScrollY();
                webView.clearHistory();
                loadUrl();
                break;
            case R.id.btn_complete:
                fontManagePopup.dismiss();
                break;
        }
    }

    private void showLoginDialog() {
        loginHelper.showDialog();
    }

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
        loadView();
        setWebView();
        slidingMenu.disapbleSlide();
        // init popup
        View popview = getLayoutInflater().inflate(R.layout.font_setting_popup, null);
        fontManagePopup = new PopupWindow(popview, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        fontManagePopup.setTouchable(true);
        fontManagePopup.setOutsideTouchable(true);
        fontManagePopup.setBackgroundDrawable(new BitmapDrawable(getResources(), (Bitmap) null));
        modeNightImg = popview.findViewById(R.id.mode_night_img);
        fontItems = new View[3];
        fontItems[0] = popview.findViewById(R.id.font_normal);
        fontItems[1] = popview.findViewById(R.id.font_big);
        fontItems[2] = popview.findViewById(R.id.font_large);

        topic = (Topic) getIntent().getSerializableExtra(INTENT_KEY_NEWSGROUP);
        currentArticle = (News) getIntent().getSerializableExtra(INTENT_KEY_NEWS);
        url = LogicUtil.getArticleUrl(currentArticle.getId(), null == topic);
//        url = "http://mp.weixin.qq.com/s?__biz=MjM5MTUxNTk0MA==&mid=205339850&idx=2&sn=03d525395b072885254d26b1a2fd9e3f&3rd=MzA3MDU4NTYzMw==&scene=6#rd";
        loadUrl();
        slidingMenu.setTrigerFromEdge(true);
        setMenuBlock();
        loginHelper = new LoginHelper(this);
        loginHelper.setLoginResultListener(this);
        //        bottomBarHandler.postDelayed(hideBottomBar, 2000);
        //        webView.loadUrl("http://www.baidu.com");
        ViewGroup rootView = (ViewGroup) f(R.id.detail_root);
        if (null == topic) {
            if(currentArticle.ableWa()) {
                UserGuideUtil.checkGuide(UserGuideUtil.GUIDE_DETAIL_WA, rootView);
            }
        }
        else {
            UserGuideUtil.checkGuide(UserGuideUtil.GUIDE_DETAIL_CAT, rootView);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        webView.destroy();
        fontManagePopup.dismiss();
    }

    @Override
    protected void onDownSlide() {
        if (vBottomBar.getVisibility() == View.GONE) {
            handler.post(showBottomBar);
        }
    }

    @Override
    protected void onLeftSlide() {
        if (!slidingMenu.isMenuOpened()) {
            startActivity(CommentActivity.getIntent(this, currentArticle.getTid(), null, null, currentArticle.getId()));
        }
    }

    @Override
    protected void onRightSlide() {
        if (!slidingMenu.isMenuOpened()) {
            finish();
        }
    }

    @Override
    protected void onUpSlide() {
        if (vBottomBar.getVisibility() == View.VISIBLE) {
            handler.post(hideBottomBar);
        }
    }

    private void setMenuBlock() {

        if (null == topic) {
            slidingMenu.disapbleSlide();
            f(R.id.bt_menu).setVisibility(View.GONE);
            f(R.id.bt_dig).setVisibility(currentArticle.ableWa() ? View.VISIBLE:View.GONE);
        } else {
            f(R.id.bt_dig).setVisibility(View.GONE);
            f(R.id.bt_menu).setVisibility(View.VISIBLE);
            tvTopicTitle.setText(topic.getTitle());
            slidingMenu.setTrigerFromEdge(false);
            adapter = new FastAdapter() {

                @Override
                public int getCount() {
                    return topic.getArticles().size();
                }

                @Override
                public View getView(int position, View v, ViewGroup parent) {
                    TopicArticleItem article = topic.getArticles().get(position);
                    TextView tvTitle = null;
                    if (null == v) {
                        v = LayoutInflater.from(ArticleActivity.this).inflate(R.layout.topic_article_item, parent, false);
                        v.setOnClickListener(listenerForMenuArticle);
                        v.setClickable(true);
                        tvTitle = f(R.id.tv_news_title, v);
                    } else {
                        tvTitle = f(R.id.tv_news_title, v);
                    }

                    v.setTag(2 << 24, article);

                    tvTitle.setText(article.getTitle());
                    if (topic.getArticles().get(position).getId().equals(currentArticle.getId())) {
                        tvTitle.setTextColor(Color.RED);
                    } else {
                        //标题颜色
                        tvTitle.setTextColor(UserConfig.isReadedArticle(article.getId()) ? MyApp.getMyTheme().getThemeColor(R.attr.font_minor_color) : MyApp.getMyTheme().getThemeColor(R.attr.font_main_color) );
                    }

                    TextView tvMedia = f(R.id.tv_news_src, v);
                    tvMedia.setText(article.getMedia() + "  " + DateUtil.autoFormat(article.getTime()));
                    ImageView iv = f(R.id.iv_news_pic, v);
                    imgPool.bind(getImg(article.getImg()), iv);
                    return v;
                }
            };
            listView.setAdapter(adapter);
            for (int i = 0; i < topic.getNews().size(); i++) {
                if (topic.getArticles().get(i).getId().equals(currentArticle.getId())) {
                    listView.setSelection(i);
                    break;
                }
            }
        }
    }

    @id(R.id.fullWebViewContainer)
    private FrameLayout fullWebViewContainer;

    private VideoWebChromeClient webChromeClient;

    @Override
    public void onFullScreen() {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) slidingMenu.getLayoutParams();
        params.setMargins(0, 0, 0, 0);
        vBottomBar.setVisibility(View.INVISIBLE);
    }

    @Override
    public void onExitFullScreen() {
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) slidingMenu.getLayoutParams();
        params.setMargins(0, (int) getResources().getDimension(R.dimen.abc_action_bar_default_height), 0, 0);
        vBottomBar.setVisibility(View.GONE);
    }

    @SuppressLint({"SetJavaScriptEnabled", "NewApi"})
    private void setWebView() {
        webChromeClient = new VideoWebChromeClient(webView, fullWebViewContainer, this);
        webView.setWebChromeClient(webChromeClient);
        webView.setWebViewClient(new WebViewClient() {


            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                //记录readed
                UserConfig.setReadedArticle(currentArticle.getId());
                cancelLoading();
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                showLoading();
                super.onPageStarted(view, url, favicon);
            }

            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                super.onReceivedError(view, errorCode, description, failingUrl);
                if (!Constants.ERROR_HTML.equals(failingUrl)) {
                    loadErrorHtml();
                }
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return super.shouldOverrideUrlLoading(view, url);
            }
        });
        WebSettings ws = webView.getSettings();
        webView.setVerticalScrollBarEnabled(true);
        webView.setHorizontalScrollBarEnabled(false);
        webView.setBackgroundColor(Color.TRANSPARENT);
        ws.setUseWideViewPort(true);// 可任意比例缩放
        ws.setAppCacheEnabled(true);
//        ws.setPluginState(WebSettings.PluginState.ON);
        //        webView.getSettings().setBuiltInZoomControls(true);
        ws.setSaveFormData(true);
        ws.setUseWideViewPort(true);
//        ws.setLoadWithOverviewMode(true);
//        ws.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
        ws.setJavaScriptEnabled(true);


//        ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);// 排版适应屏幕
//        ws.setUseWideViewPort(true);// 可任意比例缩放
//        ws.setLoadWithOverviewMode(true);// setUseWideViewPort方法设置webview推荐使用的窗口。setLoadWithOverviewMode方法是设置webview加载的页面的模式。

    }

    private void shareLog() {
        Requester.shareLog("article", currentArticle.getId(), new HttpCallBack<DefaultStringWrapper>() {
            @Override
            protected void onNetError() {

            }

            @Override
            protected void onServerError(DefaultStringWrapper data) {

            }

            @Override
            public void onSucceed(DefaultStringWrapper data) {

            }
        });
    }

    private void shareNews() {
        final String srcUrl = getSrcUrl();
        shareDialog = ShareDialog.getShareDialog(this, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareDialog.dismiss();
                String imgUrl = em(currentArticle.getImg()) ? ServerConfig.DEFAULT_SHARE_IMG : currentArticle.getImg();
                switch (v.getId()) {
                    case R.id.share_qq:
                        shareToQq(currentArticle.getTitle(), currentArticle.getSummary(), imgUrl, srcUrl);
                        break;
                    case R.id.share_qq_zone:
                        shareToQqZone(currentArticle.getTitle(), currentArticle.getSummary(), imgUrl, srcUrl);
                        break;
                    case R.id.share_weibo:
                        shareToWeibo(currentArticle.getTitle(), currentArticle.getSummary(), imgUrl, srcUrl);
                        break;
                    case R.id.share_weixin:
                        shareToWeixin(currentArticle.getTitle(), currentArticle.getSummary(), imgUrl, srcUrl);
                        break;
                    case R.id.share_weixin_friends:
                        shareToWeixinFriendCircle(currentArticle.getTitle(), currentArticle.getSummary(), imgUrl, srcUrl);
                        break;
                    case R.id.share_url:
                        shareCopyUrl(srcUrl);
                        break;
                }
                shareLog();
            }
        });
        shareDialog.show();
    }

    private void cancelLoading() {
        progressBar.setVisibility(View.GONE);
    }

    private void showLoading() {
        progressBar.setVisibility(View.VISIBLE);
    }

    private void freshCmtNum() {
        TextView tvNum = (TextView)findViewById(R.id.tv_cmt_num);
        if (currentArticle.getComments_num() == 0) {
            tvNum.setVisibility(View.GONE);
        } else {
            tvNum.setVisibility(View.VISIBLE);
            if (currentArticle.getComments_num() > 99) {
                tvNum.setText("99+");
            } else {
                tvNum.setText(currentArticle.getComments_num() + "");
            }
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("杂谈文章页");
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("杂谈文章页");
    }
}

